//
//  LKTestpageNameCakeCell.m
//  YLHelper
//
//  Created by she1323 on 2018/5/9.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "LKTestpageNameCakeCell.h"
#define random(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)/255.0]

#define randomColor random(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))



@implementation LKTestpageNameCakeCell

- (void)awakeFromNib {
    [super awakeFromNib];

}
-(void)setDetailModel:(LKTestDetailModel *)detailModel{
    _detailModel = detailModel;
    NSMutableArray *weakpointsArra = [[NSMutableArray alloc] init];
    NSInteger currentValue = 0;
    for (LKWeakPoints *weakPointsModel in self.detailModel.weakPoints) {
        PNPieChartDataItem *item = [PNPieChartDataItem dataItemWithValue:[weakPointsModel.correctRate integerValue] color:randomColor description:weakPointsModel.knowledgePointName];
        currentValue += [weakPointsModel.correctRate integerValue];
        [weakpointsArra addObject:item];
    }
    if (currentValue != 100) {
        PNPieChartDataItem *item = [PNPieChartDataItem dataItemWithValue:100 - currentValue color:[UIColor redColor] description:@"基础知识"];
        [weakpointsArra addObject:item];
    }
    // 圆饼图
    PNPieChart *pieChart = [[PNPieChart alloc] initWithFrame:CGRectMake(0, 0, 120.0, 120.0) items:weakpointsArra];
    pieChart.descriptionTextColor = [UIColor clearColor];
    pieChart.descriptionTextFont  = [UIFont fontWithName:@"Avenir-Medium" size:14.0];
    UIView *legend = [pieChart getLegendWithMaxWidth:120];
    legend.frame = CGRectMake(WIDTH - 37 - 150, 21, 120, 120);
    [self.cakepieBgView addSubview:legend];
    pieChart.hasLegend = YES;
    pieChart.legendStyle =  PNLegendItemStyleSerial;
    pieChart.legendPosition = PNLegendPositionTop;
    [pieChart strokeChart];
    [self.cakepieBgView addSubview:pieChart];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
